<!DOCTYPE html>
<html>
<head>
    

    
<!-- Tencent Speed -->
<script>var _speedMark = new Date()</script>
<!-- End Tencent Speed -->
<!-- Tencent Analysis -->
<script async src="//tajs.qq.com/stats?sId=61422473"></script>
<!-- End Tencent Analysis -->


    



    <meta charset="utf-8">
    
    
    
    <title>java获取redis的日志信息和动态监控信息 | z77z的小码窝 | 年少无为，卖码为生。</title>
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    
    <meta name="theme-color" content="#ffff00">
    
    
    <meta name="keywords" content="redis,jedis,监控">
    <meta name="description" content="效果展示

                
                    
                    
                
                实时监控">
<meta property="og:type" content="article">
<meta property="og:title" content="java获取redis的日志信息和动态监控信息">
<meta property="og:url" content="http://z77z.oschina.io/2017/04/04/java获取redis的日志信息和动态监控信息/index.html">
<meta property="og:site_name" content="z77z的小码窝">
<meta property="og:description" content="效果展示

                
                    
                    
                
                实时监控">
<meta property="og:image" content="http://img.blog.csdn.net/20170404181255324?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvcXFfMjA5NTQ5NTk=/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/SouthEast">
<meta property="og:image" content="http://img.blog.csdn.net/20170404181332831?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvcXFfMjA5NTQ5NTk=/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/SouthEast">
<meta property="og:updated_time" content="2017-04-04T11:26:02.996Z">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="java获取redis的日志信息和动态监控信息">
<meta name="twitter:description" content="效果展示

                
                    
                    
                
                实时监控">
<meta name="twitter:image" content="http://img.blog.csdn.net/20170404181255324?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvcXFfMjA5NTQ5NTk=/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/SouthEast">
    
        <link rel="alternate" type="application/atom+xml" title="z77z的小码窝" href="/atom.xml">
    
    <link rel="shortcut icon" href="/favicon.ico">
    <link rel="stylesheet" href="/css/style.css?v=1.4.3">
    <script>window.lazyScripts=[]</script>
</head>

<body>
    <div id="loading" class="active"></div>

    <aside id="menu" class="hide" >
  <div class="inner flex-row-vertical">
    <a href="javascript:;" class="header-icon waves-effect waves-circle waves-light" id="menu-off">
        <i class="icon icon-lg icon-close"></i>
    </a>
    <div class="brand-wrap" style="background-image:url(/img/brand.jpg)">
      <div class="brand">
        <a href="/" class="avatar waves-effect waves-circle waves-light">
          <img src="/img/avatar.jpg">
        </a>
        <hgroup class="introduce">
          <h5 class="nickname">邹海清</h5>
          <a href="mailto:1093615728@qq.com" title="1093615728@qq.com" class="mail">1093615728@qq.com</a>
        </hgroup>
      </div>
    </div>
    <div class="scroll-wrap flex-col">
      <ul class="nav">
        
            <li class="waves-block waves-effect">
              <a href="/"  >
                <i class="icon icon-lg icon-home"></i>
                主页
              </a>
            </li>
        
            <li class="waves-block waves-effect">
              <a href="/archives"  >
                <i class="icon icon-lg icon-archives"></i>
                归档
              </a>
            </li>
        
            <li class="waves-block waves-effect">
              <a href="/tags"  >
                <i class="icon icon-lg icon-tags"></i>
                标签
              </a>
            </li>
        
            <li class="waves-block waves-effect">
              <a href="https://git.oschina.net/z77z" target="_blank" >
                <i class="icon icon-lg icon-git"></i>
                git
              </a>
            </li>
        
            <li class="waves-block waves-effect">
              <a href="http://t.qq.com/zouhaiqing123" target="_blank" >
                <i class="icon icon-lg icon-weibo"></i>
                微博
              </a>
            </li>
        
            <li class="waves-block waves-effect">
              <a href="/custom"  >
                <i class="icon icon-lg icon-link"></i>
                404页面测试
              </a>
            </li>
        
      </ul>
    </div>
  </div>
</aside>

    <main id="main">
        <header class="top-header" id="header">
    <div class="flex-row">
        <a href="javascript:;" class="header-icon waves-effect waves-circle waves-light on" id="menu-toggle">
          <i class="icon icon-lg icon-navicon"></i>
        </a>
        <div class="flex-col header-title ellipsis">java获取redis的日志信息和动态监控信息</div>
        
        <div class="search-wrap" id="search-wrap">
            <a href="javascript:;" class="header-icon waves-effect waves-circle waves-light" id="back">
                <i class="icon icon-lg icon-chevron-left"></i>
            </a>
            <input type="text" id="key" class="search-input" autocomplete="off" placeholder="输入感兴趣的关键字">
            <a href="javascript:;" class="header-icon waves-effect waves-circle waves-light" id="search">
                <i class="icon icon-lg icon-search"></i>
            </a>
        </div>
        
        
        <a href="javascript:;" class="header-icon waves-effect waves-circle waves-light" id="menuShare">
            <i class="icon icon-lg icon-share-alt"></i>
        </a>
        
    </div>
</header>
<header class="content-header post-header">

    <div class="container fade-scale">
        <h1 class="title">java获取redis的日志信息和动态监控信息</h1>
        <h5 class="subtitle">
            
                <time datetime="2017-04-04T07:21:14.000Z" itemprop="datePublished" class="page-time">
  2017-04-04
</time>


            
        </h5>
    </div>

    


</header>


<div class="container body-wrap">
    
    <aside class="post-widget">
        <nav class="post-toc-wrap" id="post-toc">
            <h4>TOC</h4>
            <ol class="post-toc"><li class="post-toc-item post-toc-level-2"><a class="post-toc-link" href="#效果展示"><span class="post-toc-number">1.</span> <span class="post-toc-text">效果展示</span></a></li><li class="post-toc-item post-toc-level-2"><a class="post-toc-link" href="#Redis配置"><span class="post-toc-number">2.</span> <span class="post-toc-text">Redis配置</span></a></li><li class="post-toc-item post-toc-level-2"><a class="post-toc-link" href="#java部分代码实现"><span class="post-toc-number">3.</span> <span class="post-toc-text">java部分代码实现</span></a></li></ol>
        </nav>
    </aside>
    
<article id="post-java获取redis的日志信息和动态监控信息"
  class="post-article article-type-post fade" itemprop="blogPost">

    <div class="post-card">
        <h1 class="post-card-title">java获取redis的日志信息和动态监控信息</h1>
        <div class="post-meta">
            <time class="post-time" title="2017-04-04 15:21:14" datetime="2017-04-04T07:21:14.000Z"  itemprop="datePublished">2017-04-04</time>

            


            
<span id="busuanzi_container_page_pv" title="文章总阅读量" style='display:none'>
    <i class="icon icon-eye icon-pr"></i><span id="busuanzi_value_page_pv"></span>
</span>


            

        </div>
        <div class="post-content" id="post-content" itemprop="postContent">
            <h2 id="效果展示"><a href="#效果展示" class="headerlink" title="效果展示"></a>效果展示</h2><hr>
<figure class="image-bubble">
                <div class="img-lightbox">
                    <div class="overlay"></div>
                    <img src="http://img.blog.csdn.net/20170404181255324?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvcXFfMjA5NTQ5NTk=/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/SouthEast" alt="实时监控" title="">
                </div>
                <div class="image-caption">实时监控</div>
            </figure>
<figure class="image-bubble">
                <div class="img-lightbox">
                    <div class="overlay"></div>
                    <img src="http://img.blog.csdn.net/20170404181332831?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvcXFfMjA5NTQ5NTk=/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/SouthEast" alt="redis环境信息和日志列表" title="">
                </div>
                <div class="image-caption">redis环境信息和日志列表</div>
            </figure>
<h2 id="Redis配置"><a href="#Redis配置" class="headerlink" title="Redis配置"></a>Redis配置</h2><hr>
<p>在windows下安装的redis，在安装目录找到<code>redis.windows.conf</code>文件，修改以下字段（按实际情况设置）：</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div></pre></td><td class="code"><pre><div class="line">slowlog-log-slower-than 100</div><div class="line"></div><div class="line">slowlog-max-len 1000000</div></pre></td></tr></table></figure>
<p>slowlog-log-slower-than：是配置需要日志记录的命令执行时间，单位是微秒，也就是说配置为100，会记录命令执行时间为0.1ms以上的记录。如果设置为0，就会记录所有执行过的命令。</p>
<p>slowlog-max-len：是配置日志记录的条数，因为这个日志也是存储在内存中的，所以不需要担心记录日志会影响性能，但是会消耗一定内存。</p>
<p>完成对这些信息的获取主要还是利用redis的一些命令，如果是win系统下安装的redis，在安装目录运行<code>redis-cli.exe</code>这个文件，输入<code>info</code>，再回车，就可以看到输出很多字段的参数，部分具体参数对应的意思如下：</p>
<ul>
<li>server : 一般 Redis 服务器信息，包含以下域：</li>
<li>redis_version : Redis 服务器版本</li>
<li>redis_git_sha1 : Git SHA1</li>
<li>redis_git_dirty : Git dirty flag</li>
<li>os : Redis 服务器的宿主操作系统</li>
<li>arch_bits : 架构（32 或 64 位）</li>
<li>multiplexing_api : Redis 所使用的事件处理机制</li>
<li>gcc_version : 编译 Redis 时所使用的 GCC 版本</li>
<li>process_id : 服务器进程的 PID</li>
<li>run_id : Redis 服务器的随机标识符（用于 Sentinel 和集群）</li>
<li>tcp_port : TCP/IP 监听端口</li>
<li>uptime_in_seconds : 自 Redis 服务器启动以来，经过的秒数</li>
<li>uptime_in_days : 自 Redis 服务器启动以来，经过的天数</li>
<li>lru_clock : 以分钟为单位进行自增的时钟，用于 LRU 管理</li>
<li>clients : 已连接客户端信息，包含以下域：</li>
<li>connected_clients : 已连接客户端的数量（不包括通过从属服务器连接的客户端）</li>
<li>client_longest_output_list : 当前连接的客户端当中，最长的输出列表</li>
<li>client_longest_input_buf : 当前连接的客户端当中，最大输入缓存</li>
<li>blocked_clients : 正在等待阻塞命令（BLPOP、BRPOP、BRPOPLPUSH）的客户端的数量</li>
<li>memory : 内存信息，包含以下域：</li>
<li>used_memory : 由 Redis 分配器分配的内存总量，以字节（byte）为单位</li>
<li>used_memory_human : 以人类可读的格式返回 Redis 分配的内存总量</li>
<li>used_memory_rss : 从操作系统的角度，返回 Redis 已分配的内存总量（俗称常驻集大小）。这个值和 top 、 ps 等命令的输出一致。</li>
<li>used_memory_peak : Redis 的内存消耗峰值（以字节为单位）</li>
<li>used_memory_peak_human : 以人类可读的格式返回 Redis 的内存消耗峰值</li>
<li>used_memory_lua : Lua 引擎所使用的内存大小（以字节为单位）</li>
<li>mem_fragmentation_ratio : used_memory_rss 和 used_memory 之间的比率</li>
<li>mem_allocator : 在编译时指定的， Redis 所使用的内存分配器。可以是 libc 、 jemalloc 或者 tcmalloc 。<br>在理想情况下， used_memory_rss 的值应该只比 used_memory 稍微高一点儿。<br>当 rss &gt; used ，且两者的值相差较大时，表示存在（内部或外部的）内存碎片。<br>内存碎片的比率可以通过 mem_fragmentation_ratio 的值看出。<br>当 used &gt; rss 时，表示 Redis 的部分内存被操作系统换出到交换空间了，在这种情况下，操作可能会产生明显的延迟。<br>当 Redis 释放内存时，分配器可能会，也可能不会，将内存返还给操作系统。<br>如果 Redis 释放了内存，却没有将内存返还给操作系统，那么 used_memory 的值可能和操作系统显示的 Redis 内存占用并不一致。<br>查看 used_memory_peak 的值可以验证这种情况是否发生。</li>
<li>persistence : RDB 和 AOF 的相关信息</li>
<li>stats : 一般统计信息</li>
<li>replication : 主/从复制信息</li>
<li>cpu : CPU 计算量统计信息</li>
<li>commandstats : Redis 命令统计信息</li>
<li>cluster : Redis 集群信息</li>
<li>keyspace : 数据库相关的统计信息</li>
</ul>
<h2 id="java部分代码实现"><a href="#java部分代码实现" class="headerlink" title="java部分代码实现"></a>java部分代码实现</h2><hr>
<p>上面是命令窗的方式，使用java的话，我们就是借助jedis这个框架来帮我们完成：</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div><div class="line">18</div><div class="line">19</div><div class="line">20</div><div class="line">21</div><div class="line">22</div><div class="line">23</div><div class="line">24</div><div class="line">25</div><div class="line">26</div><div class="line">27</div><div class="line">28</div><div class="line">29</div><div class="line">30</div><div class="line">31</div><div class="line">32</div><div class="line">33</div><div class="line">34</div><div class="line">35</div><div class="line">36</div><div class="line">37</div><div class="line">38</div><div class="line">39</div><div class="line">40</div><div class="line">41</div><div class="line">42</div><div class="line">43</div><div class="line">44</div><div class="line">45</div><div class="line">46</div><div class="line">47</div><div class="line">48</div><div class="line">49</div><div class="line">50</div><div class="line">51</div><div class="line">52</div><div class="line">53</div><div class="line">54</div><div class="line">55</div><div class="line">56</div><div class="line">57</div><div class="line">58</div><div class="line">59</div><div class="line">60</div><div class="line">61</div><div class="line">62</div><div class="line">63</div><div class="line">64</div><div class="line">65</div><div class="line">66</div><div class="line">67</div><div class="line">68</div><div class="line">69</div><div class="line">70</div><div class="line">71</div><div class="line">72</div><div class="line">73</div><div class="line">74</div><div class="line">75</div></pre></td><td class="code"><pre><div class="line"><span class="meta">@Component</span></div><div class="line"><span class="keyword">public</span> <span class="class"><span class="keyword">class</span> <span class="title">RedisUtil</span> </span>&#123;</div><div class="line"></div><div class="line">	<span class="meta">@Autowired</span></div><div class="line">	JedisPool jedisPool;</div><div class="line"></div><div class="line">	<span class="comment">// 获取redis 服务器信息</span></div><div class="line">	<span class="function"><span class="keyword">public</span> String <span class="title">getRedisInfo</span><span class="params">()</span> </span>&#123;</div><div class="line"></div><div class="line">		Jedis jedis = <span class="keyword">null</span>;</div><div class="line">		<span class="keyword">try</span> &#123;</div><div class="line">			jedis = jedisPool.getResource();</div><div class="line">			Client client = jedis.getClient();</div><div class="line">			client.info();</div><div class="line">			String info = client.getBulkReply();</div><div class="line">			<span class="keyword">return</span> info;</div><div class="line">		&#125; <span class="keyword">finally</span> &#123;</div><div class="line">			<span class="comment">// 返还到连接池</span></div><div class="line">			jedis.close();</div><div class="line">		&#125;</div><div class="line">	&#125;</div><div class="line"></div><div class="line">	<span class="comment">// 获取日志列表</span></div><div class="line">	<span class="function"><span class="keyword">public</span> List&lt;Slowlog&gt; <span class="title">getLogs</span><span class="params">(<span class="keyword">long</span> entries)</span> </span>&#123;</div><div class="line">		Jedis jedis = <span class="keyword">null</span>;</div><div class="line">		<span class="keyword">try</span> &#123;</div><div class="line">			jedis = jedisPool.getResource();</div><div class="line">			List&lt;Slowlog&gt; logList = jedis.slowlogGet(entries);</div><div class="line">			<span class="keyword">return</span> logList;</div><div class="line">		&#125; <span class="keyword">finally</span> &#123;</div><div class="line">			<span class="comment">// 返还到连接池</span></div><div class="line">			jedis.close();</div><div class="line">		&#125;</div><div class="line">	&#125;</div><div class="line"></div><div class="line">	<span class="comment">// 获取日志条数</span></div><div class="line">	<span class="function"><span class="keyword">public</span> Long <span class="title">getLogsLen</span><span class="params">()</span> </span>&#123;</div><div class="line">		Jedis jedis = <span class="keyword">null</span>;</div><div class="line">		<span class="keyword">try</span> &#123;</div><div class="line">			jedis = jedisPool.getResource();</div><div class="line">			<span class="keyword">long</span> logLen = jedis.slowlogLen();</div><div class="line">			<span class="keyword">return</span> logLen;</div><div class="line">		&#125; <span class="keyword">finally</span> &#123;</div><div class="line">			<span class="comment">// 返还到连接池</span></div><div class="line">			jedis.close();</div><div class="line">		&#125;</div><div class="line">	&#125;</div><div class="line"></div><div class="line">	<span class="comment">// 清空日志</span></div><div class="line">	<span class="function"><span class="keyword">public</span> String <span class="title">logEmpty</span><span class="params">()</span> </span>&#123;</div><div class="line">		Jedis jedis = <span class="keyword">null</span>;</div><div class="line">		<span class="keyword">try</span> &#123;</div><div class="line">			jedis = jedisPool.getResource();</div><div class="line">			<span class="keyword">return</span> jedis.slowlogReset();</div><div class="line">		&#125; <span class="keyword">finally</span> &#123;</div><div class="line">			<span class="comment">// 返还到连接池</span></div><div class="line">			jedis.close();</div><div class="line">		&#125;</div><div class="line">	&#125;</div><div class="line"></div><div class="line">	<span class="comment">// 获取占用内存大小</span></div><div class="line">	<span class="function"><span class="keyword">public</span> Long <span class="title">dbSize</span><span class="params">()</span> </span>&#123;</div><div class="line">		Jedis jedis = <span class="keyword">null</span>;</div><div class="line">		<span class="keyword">try</span> &#123;</div><div class="line">			jedis = jedisPool.getResource();</div><div class="line">			<span class="comment">// TODO 配置redis服务信息</span></div><div class="line">			Client client = jedis.getClient();</div><div class="line">			client.dbSize();</div><div class="line">			<span class="keyword">return</span> client.getIntegerReply();</div><div class="line">		&#125; <span class="keyword">finally</span> &#123;</div><div class="line">			<span class="comment">// 返还到连接池</span></div><div class="line">			jedis.close();</div><div class="line">		&#125;</div><div class="line">	&#125;</div><div class="line">&#125;</div></pre></td></tr></table></figure>
<p>这样输出的都是和控制台一样的字符串，所以还需要sevice来对数据进行封装：</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div><div class="line">18</div><div class="line">19</div><div class="line">20</div><div class="line">21</div><div class="line">22</div><div class="line">23</div><div class="line">24</div><div class="line">25</div><div class="line">26</div><div class="line">27</div><div class="line">28</div><div class="line">29</div><div class="line">30</div><div class="line">31</div><div class="line">32</div><div class="line">33</div><div class="line">34</div><div class="line">35</div><div class="line">36</div><div class="line">37</div><div class="line">38</div><div class="line">39</div><div class="line">40</div><div class="line">41</div><div class="line">42</div><div class="line">43</div><div class="line">44</div><div class="line">45</div><div class="line">46</div><div class="line">47</div><div class="line">48</div><div class="line">49</div><div class="line">50</div><div class="line">51</div><div class="line">52</div><div class="line">53</div><div class="line">54</div><div class="line">55</div><div class="line">56</div><div class="line">57</div><div class="line">58</div><div class="line">59</div><div class="line">60</div><div class="line">61</div><div class="line">62</div><div class="line">63</div><div class="line">64</div><div class="line">65</div><div class="line">66</div><div class="line">67</div><div class="line">68</div><div class="line">69</div><div class="line">70</div><div class="line">71</div><div class="line">72</div><div class="line">73</div><div class="line">74</div><div class="line">75</div><div class="line">76</div><div class="line">77</div><div class="line">78</div><div class="line">79</div><div class="line">80</div><div class="line">81</div><div class="line">82</div><div class="line">83</div><div class="line">84</div><div class="line">85</div><div class="line">86</div><div class="line">87</div><div class="line">88</div><div class="line">89</div><div class="line">90</div><div class="line">91</div><div class="line">92</div><div class="line">93</div><div class="line">94</div><div class="line">95</div></pre></td><td class="code"><pre><div class="line"><span class="meta">@Service</span></div><div class="line"><span class="keyword">public</span> <span class="class"><span class="keyword">class</span> <span class="title">RedisService</span> </span>&#123;</div><div class="line">	</div><div class="line">	<span class="meta">@Autowired</span></div><div class="line">	RedisUtil redisUtil;</div><div class="line">	</div><div class="line">	<span class="function"><span class="keyword">public</span> List&lt;RedisInfoDetail&gt; <span class="title">getRedisInfo</span><span class="params">()</span> </span>&#123;</div><div class="line">		<span class="comment">//获取redis服务器信息</span></div><div class="line">		String info = redisUtil.getRedisInfo();</div><div class="line">		List&lt;RedisInfoDetail&gt; ridList = <span class="keyword">new</span> ArrayList&lt;RedisInfoDetail&gt;();</div><div class="line">		String[] strs = info.split(<span class="string">"\n"</span>);</div><div class="line">		RedisInfoDetail rif = <span class="keyword">null</span>;</div><div class="line">		<span class="keyword">if</span> (strs != <span class="keyword">null</span> &amp;&amp; strs.length &gt; <span class="number">0</span>) &#123;</div><div class="line">			<span class="keyword">for</span> (<span class="keyword">int</span> i = <span class="number">0</span>; i &lt; strs.length; i++) &#123;</div><div class="line">				rif = <span class="keyword">new</span> RedisInfoDetail();</div><div class="line">				String s = strs[i];</div><div class="line">				String[] str = s.split(<span class="string">":"</span>);</div><div class="line">				<span class="keyword">if</span> (str != <span class="keyword">null</span> &amp;&amp; str.length &gt; <span class="number">1</span>) &#123;</div><div class="line">					String key = str[<span class="number">0</span>];</div><div class="line">					String value = str[<span class="number">1</span>];</div><div class="line">					rif.setKey(key);</div><div class="line">					rif.setValue(value);</div><div class="line">					ridList.add(rif);</div><div class="line">				&#125;</div><div class="line">			&#125;</div><div class="line">		&#125;</div><div class="line">		<span class="keyword">return</span> ridList;</div><div class="line">	&#125;</div><div class="line">	</div><div class="line">	<span class="comment">//获取redis日志列表</span></div><div class="line">	<span class="function"><span class="keyword">public</span> List&lt;Operate&gt; <span class="title">getLogs</span><span class="params">(<span class="keyword">long</span> entries)</span> </span>&#123;</div><div class="line">        List&lt;Slowlog&gt; list = redisUtil.getLogs(entries);</div><div class="line">		List&lt;Operate&gt; opList = <span class="keyword">null</span>;</div><div class="line">		Operate op  = <span class="keyword">null</span>;</div><div class="line">		<span class="keyword">boolean</span> flag = <span class="keyword">false</span>;</div><div class="line">		<span class="keyword">if</span> (list != <span class="keyword">null</span> &amp;&amp; list.size() &gt; <span class="number">0</span>) &#123;</div><div class="line">			opList = <span class="keyword">new</span> LinkedList&lt;Operate&gt;();</div><div class="line">			<span class="keyword">for</span> (Slowlog sl : list) &#123;</div><div class="line">				String args = JSON.toJSONString(sl.getArgs());</div><div class="line">				<span class="keyword">if</span> (args.equals(<span class="string">"[\"PING\"]"</span>) || args.equals(<span class="string">"[\"SLOWLOG\",\"get\"]"</span>) || args.equals(<span class="string">"[\"DBSIZE\"]"</span>) || args.equals(<span class="string">"[\"INFO\"]"</span>)) &#123;</div><div class="line">					<span class="keyword">continue</span>;</div><div class="line">				&#125;	</div><div class="line">				op = <span class="keyword">new</span> Operate();</div><div class="line">				flag = <span class="keyword">true</span>;</div><div class="line">				op.setId(sl.getId());</div><div class="line">				op.setExecuteTime(getDateStr(sl.getTimeStamp() * <span class="number">1000</span>));</div><div class="line">				op.setUsedTime(sl.getExecutionTime()/<span class="number">1000.0</span> + <span class="string">"ms"</span>);</div><div class="line">				op.setArgs(args);</div><div class="line">				opList.add(op);</div><div class="line">			&#125;</div><div class="line">		&#125; </div><div class="line">		<span class="keyword">if</span> (flag) </div><div class="line">			<span class="keyword">return</span> opList;</div><div class="line">		<span class="keyword">else</span> </div><div class="line">			<span class="keyword">return</span> <span class="keyword">null</span>;</div><div class="line">	&#125;</div><div class="line">	<span class="comment">//获取日志总数</span></div><div class="line">	<span class="function"><span class="keyword">public</span> Long <span class="title">getLogLen</span><span class="params">()</span> </span>&#123;</div><div class="line">		<span class="keyword">return</span> redisUtil.getLogsLen();</div><div class="line">	&#125;</div><div class="line">	</div><div class="line">	<span class="comment">//清空日志</span></div><div class="line">	<span class="function"><span class="keyword">public</span> String <span class="title">logEmpty</span><span class="params">()</span> </span>&#123;</div><div class="line">		<span class="keyword">return</span> redisUtil.logEmpty();</div><div class="line">	&#125;</div><div class="line">	<span class="comment">//获取当前数据库中key的数量</span></div><div class="line">	<span class="function"><span class="keyword">public</span> Map&lt;String,Object&gt; <span class="title">getKeysSize</span><span class="params">()</span> </span>&#123;</div><div class="line">		<span class="keyword">long</span> dbSize = redisUtil.dbSize();</div><div class="line">		Map&lt;String,Object&gt; map = <span class="keyword">new</span> HashMap&lt;String, Object&gt;();</div><div class="line">		map.put(<span class="string">"create_time"</span>, <span class="keyword">new</span> Date().getTime());</div><div class="line">		map.put(<span class="string">"dbSize"</span>, dbSize);</div><div class="line">		<span class="keyword">return</span> map;</div><div class="line">	&#125;</div><div class="line">	</div><div class="line">	<span class="comment">//获取当前redis使用内存大小情况</span></div><div class="line">	<span class="function"><span class="keyword">public</span> Map&lt;String,Object&gt; <span class="title">getMemeryInfo</span><span class="params">()</span> </span>&#123;</div><div class="line">		String[] strs = redisUtil.getRedisInfo().split(<span class="string">"\n"</span>);</div><div class="line">		Map&lt;String, Object&gt; map = <span class="keyword">null</span>;</div><div class="line">		<span class="keyword">for</span> (<span class="keyword">int</span> i = <span class="number">0</span>; i &lt; strs.length; i++) &#123;</div><div class="line">			String s = strs[i];</div><div class="line">			String[] detail = s.split(<span class="string">":"</span>);</div><div class="line">			<span class="keyword">if</span> (detail[<span class="number">0</span>].equals(<span class="string">"used_memory"</span>)) &#123;</div><div class="line">				map = <span class="keyword">new</span> HashMap&lt;String, Object&gt;();</div><div class="line">				map.put(<span class="string">"used_memory"</span>,detail[<span class="number">1</span>].substring(<span class="number">0</span>, detail[<span class="number">1</span>].length() - <span class="number">1</span>));</div><div class="line">				map.put(<span class="string">"create_time"</span>, <span class="keyword">new</span> Date().getTime());</div><div class="line">				<span class="keyword">break</span>;</div><div class="line">			&#125;</div><div class="line">		&#125;</div><div class="line">		<span class="keyword">return</span> map;</div><div class="line">	&#125;</div><div class="line">	<span class="function"><span class="keyword">private</span> String <span class="title">getDateStr</span><span class="params">(<span class="keyword">long</span> timeStmp)</span> </span>&#123;</div><div class="line">		SimpleDateFormat dateFormat = <span class="keyword">new</span> SimpleDateFormat(<span class="string">"yyyy-MM-dd HH:mm:ss"</span>);</div><div class="line">		<span class="keyword">return</span> dateFormat.format(<span class="keyword">new</span> Date(timeStmp));</div><div class="line">	&#125;</div><div class="line">&#125;</div></pre></td></tr></table></figure>
<p>上面我只是贴了部分核心代码，想具体去了解的可以去下载我的项目跑一下。</p>
<p>由于这个没有什么难度，只是就只是贴了些代码。后续也会一直更新，一步步将这个系统完善起来。</p>
<p>·······················································································································································</p>
<p>个人博客：<a href="http://z77z.oschina.io/">http://z77z.oschina.io/</a></p>
<p>此项目下载地址：<a href="https://git.oschina.net/z77z/springboot_mybatisplus" target="_blank" rel="external">https://git.oschina.net/z77z/springboot_mybatisplus</a></p>
<p>·······················································································································································</p>

        </div>

        <blockquote class="post-copyright">
    <div class="content">
        
<span class="post-time">
    最后更新时间：<time datetime="2017-04-04T11:26:02.996Z" itemprop="dateUpdated">2017-04-04 19:26:02</time>
</span><br>


        
    </div>
    <footer>
        <a href="http://z77z.oschina.io">
            <img src="/img/avatar.jpg" alt="邹海清">
            邹海清
        </a>
    </footer>
</blockquote>

        
<div class="page-reward">
    <a id="rewardBtn" href="javascript:;" class="page-reward-btn waves-effect waves-circle waves-light">赏</a>
</div>



        <div class="post-footer">
            
	<ul class="article-tag-list"><li class="article-tag-list-item"><a class="article-tag-list-link" href="/tags/jedis/">jedis</a></li><li class="article-tag-list-item"><a class="article-tag-list-link" href="/tags/redis/">redis</a></li><li class="article-tag-list-item"><a class="article-tag-list-link" href="/tags/监控/">监控</a></li></ul>


            
<div class="page-share-wrap">
    

<div class="page-share" id="pageShare">
    <ul class="reset share-icons">
      <li>
        <a class="weibo share-sns" target="_blank" href="http://service.weibo.com/share/share.php?url=http://z77z.oschina.io/2017/04/04/java获取redis的日志信息和动态监控信息/&title=《java获取redis的日志信息和动态监控信息》 — z77z的小码窝&pic=http://z77z.oschina.io/img/avatar.jpg" data-title="微博">
          <i class="icon icon-weibo"></i>
        </a>
      </li>
      <li>
        <a class="weixin share-sns wxFab" href="javascript:;" data-title="微信">
          <i class="icon icon-weixin"></i>
        </a>
      </li>
      <li>
        <a class="qq share-sns" target="_blank" href="http://connect.qq.com/widget/shareqq/index.html?url=http://z77z.oschina.io/2017/04/04/java获取redis的日志信息和动态监控信息/&title=《java获取redis的日志信息和动态监控信息》 — z77z的小码窝&source=" data-title=" QQ">
          <i class="icon icon-qq"></i>
        </a>
      </li>
      <li>
        <a class="facebook share-sns" target="_blank" href="https://www.facebook.com/sharer/sharer.php?u=http://z77z.oschina.io/2017/04/04/java获取redis的日志信息和动态监控信息/" data-title=" Facebook">
          <i class="icon icon-facebook"></i>
        </a>
      </li>
      <li>
        <a class="twitter share-sns" target="_blank" href="https://twitter.com/intent/tweet?text=《java获取redis的日志信息和动态监控信息》 — z77z的小码窝&url=http://z77z.oschina.io/2017/04/04/java获取redis的日志信息和动态监控信息/&via=http://z77z.oschina.io" data-title=" Twitter">
          <i class="icon icon-twitter"></i>
        </a>
      </li>
      <li>
        <a class="google share-sns" target="_blank" href="https://plus.google.com/share?url=http://z77z.oschina.io/2017/04/04/java获取redis的日志信息和动态监控信息/" data-title=" Google+">
          <i class="icon icon-google-plus"></i>
        </a>
      </li>
    </ul>
 </div>



    <a href="javascript:;" id="shareFab" class="page-share-fab waves-effect waves-circle">
        <i class="icon icon-share-alt icon-lg"></i>
    </a>
</div>



        </div>
    </div>

    
<nav class="post-nav flex-row flex-justify-between">
  
    <div class="waves-block waves-effect prev">
      <a href="/2017/04/23/SpringBoot-Mybatis_Plus学习记录之公共字段自动填充/" id="post-prev" class="post-nav-link">
        <div class="tips"><i class="icon icon-angle-left icon-lg icon-pr"></i> Prev</div>
        <h4 class="title">SpringBoot-Mybatis_Plus学习记录之公共字段自动填充</h4>
      </a>
    </div>
  

  
    <div class="waves-block waves-effect next">
      <a href="/2017/03/27/Shiro中Session和Cookie的一些思考/" id="post-next" class="post-nav-link">
        <div class="tips">Next <i class="icon icon-angle-right icon-lg icon-pl"></i></div>
        <h4 class="title">Shiro中Session和Cookie的一些思考</h4>
      </a>
    </div>
  
</nav>



    










    <div id="cloud-tie-wrapper" class="comments cloud-tie-wrapper"></div>
    <script>
    var cloudTieConfig = {
        url: 'http://z77z.oschina.io/2017/04/04/java获取redis的日志信息和动态监控信息/index.html',
        sourceId: 'java获取redis的日志信息和动态监控信息',
        productKey: '64500aaa7f0a4f6f804c4df9b5880011',
        target: 'cloud-tie-wrapper',
        pcFiles: [
            '/css/cloudTie/pc.css?v=1.4.3',
            '/js/cloudTie/pc.min.js?v=1.4.3',
        ],
        mobileFiles: [
            '/css/cloudTie/mobile.css?v=1.4.3',
            '/js/cloudTie/mobile.min.js?v=1.4.3'
        ]
    };
    </script>
    <script src="/js/cloudTie/loader.min.js?v=1.4.3"></script>







</article>

<div id="reward" class="page-modal reward-lay">
    <a class="close" href="javascript:;"><i class="icon icon-close"></i></a>
    <h3 class="reward-title">
        <i class="icon icon-quote-left"></i>
        我只要一角钱~ ~
        <i class="icon icon-quote-right"></i>
    </h3>
    <ul class="reward-items">
        
        <li>
            <img src="/img/wechat.png" title="微信打赏二维码" alt="微信打赏二维码">
            <p>微信</p>
        </li>
        

        
        <li>
            <img src="/img/alipay.jpg" title="支付宝打赏二维码" alt="支付宝打赏二维码">
            <p>支付宝</p>
        </li>
        
    </ul>
</div>



</div>

        <footer class="footer">
    <div class="top">
        
<p>
    <span id="busuanzi_container_site_uv" style='display:none'>
        站点总访客数：<span id="busuanzi_value_site_uv"></span>
    </span>
    <span id="busuanzi_container_site_pv" style='display:none'>
        站点总访问量：<span id="busuanzi_value_site_pv"></span>
    </span>
</p>


        <p>
            
                <span><a href="/atom.xml" target="_blank" class="rss" title="rss"><i class="icon icon-lg icon-rss"></i></a></span>
            
            <span>博客内容遵循<a rel="license" href="https://creativecommons.org/licenses/by-nc-sa/4.0/deed.zh">知识共享 署名 - 非商业性 - 相同方式共享 4.0 国际协议</a></span>
        </p>
    </div>
    <div class="bottom">
        <p>
            <span>Power by <a href="http://hexo.io/" target="_blank">Hexo</a> Theme <a href="https://github.com/yscoder/hexo-theme-indigo" target="_blank">indigo</a></span>
            <span>邹海清 &copy; 2016 - 2017</span>
        </p>
    </div>
</footer>

    </main>
    <div class="mask" id="mask"></div>
<a href="javascript:;" id="gotop" class="waves-effect waves-circle waves-light"><span class="icon icon-lg icon-chevron-up"></span></a>



<div class="global-share" id="globalShare">
    <ul class="reset share-icons">
      <li>
        <a class="weibo share-sns" target="_blank" href="http://service.weibo.com/share/share.php?url=http://z77z.oschina.io/2017/04/04/java获取redis的日志信息和动态监控信息/&title=《java获取redis的日志信息和动态监控信息》 — z77z的小码窝&pic=http://z77z.oschina.io/img/avatar.jpg" data-title="微博">
          <i class="icon icon-weibo"></i>
        </a>
      </li>
      <li>
        <a class="weixin share-sns wxFab" href="javascript:;" data-title="微信">
          <i class="icon icon-weixin"></i>
        </a>
      </li>
      <li>
        <a class="qq share-sns" target="_blank" href="http://connect.qq.com/widget/shareqq/index.html?url=http://z77z.oschina.io/2017/04/04/java获取redis的日志信息和动态监控信息/&title=《java获取redis的日志信息和动态监控信息》 — z77z的小码窝&source=" data-title=" QQ">
          <i class="icon icon-qq"></i>
        </a>
      </li>
      <li>
        <a class="facebook share-sns" target="_blank" href="https://www.facebook.com/sharer/sharer.php?u=http://z77z.oschina.io/2017/04/04/java获取redis的日志信息和动态监控信息/" data-title=" Facebook">
          <i class="icon icon-facebook"></i>
        </a>
      </li>
      <li>
        <a class="twitter share-sns" target="_blank" href="https://twitter.com/intent/tweet?text=《java获取redis的日志信息和动态监控信息》 — z77z的小码窝&url=http://z77z.oschina.io/2017/04/04/java获取redis的日志信息和动态监控信息/&via=http://z77z.oschina.io" data-title=" Twitter">
          <i class="icon icon-twitter"></i>
        </a>
      </li>
      <li>
        <a class="google share-sns" target="_blank" href="https://plus.google.com/share?url=http://z77z.oschina.io/2017/04/04/java获取redis的日志信息和动态监控信息/" data-title=" Google+">
          <i class="icon icon-google-plus"></i>
        </a>
      </li>
    </ul>
 </div>


<div class="page-modal wx-share" id="wxShare">
    <a class="close" href="javascript:;"><i class="icon icon-close"></i></a>
    <p>扫一扫，分享到微信</p>
    <img src="" alt="微信分享二维码">
</div>




    <script src="//cdn.bootcss.com/node-waves/0.7.4/waves.min.js"></script>
<script>
var BLOG = { ROOT: '/', SHARE: true, REWARD: true };



lazyScripts.push('//s95.cnzz.com/z_stat.php?id=1261081671&web_id=1261081671')

</script>

<script src="/js/main.min.js?v=1.4.3"></script>


<div class="search-panel" id="search-panel">
    <ul class="search-result" id="search-result"></ul>
</div>
<template id="search-tpl">
<li class="item">
    <a href="{path}" class="waves-block waves-effect">
        <div class="title ellipsis" title="{title}">{title}</div>
        <div class="flex-row flex-middle">
            <div class="tags ellipsis">
                {tags}
            </div>
            <time class="flex-col time">{date}</time>
        </div>
    </a>
</li>
</template>

<script src="/js/search.min.js?v=1.4.3" async></script>






<script async src="//dn-lbstatics.qbox.me/busuanzi/2.3/busuanzi.pure.mini.js"></script>



<script>
(function() {
    var OriginTitile = document.title, titleTime;
    document.addEventListener('visibilitychange', function() {
        if (document.hidden) {
            document.title = '死鬼去哪里了！';
            clearTimeout(titleTime);
        } else {
            document.title = '(つェ⊂)咦!又好了!';
            titleTime = setTimeout(function() {
                document.title = OriginTitile;
            },2000);
        }
    });
})();
</script>



</body>
</html>
